package com.springseries.poi.user.controller;

import com.springseries.poi.user.model.UserModel;
import com.springseries.poi.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/user/")
public class UserController extends AbstractController {

    @Autowired
    private UserService userService;

    @RequestMapping("getPage")
    public String getPage(){
        return "userPage";
    }

    @ResponseBody
    @RequestMapping("findAll")
    public List<UserModel> findALl(){
        return userService.findAll();
    }

    @Override
    @RequestMapping("export")
    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        List<UserModel> userList = userService.findAll();
        return new ModelAndView("userListView","userList",userList);
    }
}
